<%@ page contentType="text/html;charset=UTF-8"%>
<html>
	<head>
		<title>栏目里面-稿件管理</title>
		<%@ include file="/common/import.jsp" %>
	<%@ include file="/common/meta.jsp" %>
    <script type="text/javascript" src="${ctx}/js/easyui/extendvalidate.js"></script>
	<script type="text/javascript" >
$(function() {
	$('#manuscriptList').datagrid( {
		title : '此栏目下稿件列表',
		url : "${ctx}/wcm/manuscript/list!data.action?channelId=${channelId}",
		loadMsg : '数据载入中，请稍后……',
		nowrap : false,
		collapsible : false,
		fitColumns : true,
		pagination : true,
		singleSelect : true,
		rownumbers : true,
		remoteSort : false,
		pageList : [10,15,20,50],
		idField : 'manuscriptId',
		columns : [ [ 
		   {field : 'title',title : '标题',width : 320},
		   {field : 'channelCode',title : '所属栏目',width : 100}, 
		{field : 'type',title : '类型',width : 80,
			formatter : function(value) {
				if("1"==value){
					return "普通稿件";
				}else{
			        return "链接稿件";
				}
			}
		}, 
		{field : 'createdTime',title : '创建时间',width : 120,sorter : function(a, b) {return (a > b ? 1 : -1);}
		}, 
		{field : 'status',title : '当前状态',width : 80,
			formatter : function(value) {
				if( value=='0'){
					return '未发布';
				}else if(value=='1'){ 
					return '发布中';
				}else if(value=='2'){
				    return '已发布';
				}else{ 
					return '已撤销';
				}
			}
		}, {
			field : 'isQuoted',
			title : '操作',
			width : 120,
			formatter : function(value,rowData) {
			    var str="";
			    if(rowData.status=='2'){
			      //  str +="<a class='abcl' href='"+portal_url+"viewAritce?doCode=viewArtice&infoId="+rowData.manuscriptId+"'  target='_blank'>预览</a>&nbsp;&nbsp;";
			    }
			    if(rowData.status=='0' || rowData.status=='3'){
			        str +="<a href='javascript:void(0)' class='abcl' onclick=\"publishArtice('"+rowData.manuscriptId+"')\">发布</a>&nbsp;&nbsp;";
			    }else if(rowData.status=='2'){
			    	str +="<a href='javascript:void(0)' class='abcl' onclick=\"unpublish('"+rowData.manuscriptId+"')\" >撤销</a>&nbsp;&nbsp;";
			    }
			    if(rowData.status=='0' || rowData.status=='3'){
			        str +="<a href='javascript:void(0)' class='abcl' onclick=\"delManuscript('"+rowData.manuscriptId+"','"+rowData.title+"')\">删除</a>&nbsp;&nbsp;";
			    }
				return str;
			}
		}] ],

		toolbar : [ {
			text : '增加',
			iconCls : 'icon-add',
			handler : function() {
				addManuscript();
			}

		},'-', {
			text : '修改',
			iconCls : 'icon-edit',
			handler : function() {
				editManuscript();
			}
		}, '-',
		{
			text : '刷新',
			iconCls : 'icon-reload',
			handler : function() {
				reload('');
			}
		} ]
	});
});

	</script>
	</head>

	<body>
		<table class="tab_info">
			<tr>
				<th>标题</th>
				<td>
					<input name="title" id="title" value="" size="50"/>
				</td>
				<c:if test="${empty channelId}">
				<th>所属栏目</th>
				<td>
				     <select name="channelId" id="channelId"  style="width:50px;" >
				       <option  value="">全部</option>
				     </select>
				</td>
				</c:if>
				<th>状态</th>
				<td>
				     <select name="status" id="status"  style="width:100px;" >
				       <option  value="">--全部--</option>
				       <option  value="0">未发布</option>
				       <option  value="1">发布中</option>
				       <option  value="2"/>已发布</option>
				       <option  value="3"/>已撤销</option>
				     </select>
				</td>
				<td style="text-align: left;">
					<input class="bluebtn" type="button" onclick="manuscriptQuery();" value="查询"/>
				</td>
			</tr>
		</table>

		<table id="manuscriptList"></table>
		
		<div id="manuscriptAddWin" class="easyui-window" title="添加 稿件"
			style="padding:5px;float:left;top:10px;overflow: hidden;" iconCls="icon-search" closed="true" minimizable="false" maximizable="false" maximized="true" collapsible="false">
			<iframe frameborder="0" id="manuscriptAddFrame" height="100%" width="100%" scrolling="yes" frameborder="0"></iframe>
		</div>
<script type="text/javascript">
    function delManuscript(manuscriptId,title) {
	     $.messager.confirm('确认', '您确定要删除:<font color="red">' + title + '</font> ？',
			function(r) {
				if (r) {
					$.ajax( {
						type : "post",
						url : "${ctx}/wcm/manuscript/del.action?id="+ manuscriptId,
						success : function(data, textStatus) {
							var result = jQuery.parseJSON(data);
							if(result.flag=="T"){
								$.messager.alert('结果', '操作成功', 'info');	
								reload();
							}else{
								$.messager.alert('提交结果', result.msg, 'error');
							}
						}
					});
				}
			});
      }
   
var widthcount = $(document.body).width()-20; 
var leftcount = document.documentElement.scrollLeft;

	function editManuscript() {
		var node = getSelected();
		if (node) {
			var url = '${ctx}/wcm/manuscript/add.action?manuscriptId='+node.manuscriptId+'&flag=1';
			if ($.isFunction(window.parent.addTab)){
				window.location.href=url;
				//window.parent.addTab('修改稿件',url,'icon-dept');
			}else{
				/**
				$('#manuscriptAddWin').css({"width":widthcount,"height":"450px","left":leftcount});
				$('#manuscriptAddFrame').attr("src",url);
				$('#manuscriptAddWin').panel('setTitle','修改稿件');
				$('#manuscriptAddWin').window('open');
				
				**/
				window.location.href=url;
			}
		}
	}

	function addManuscript() {
		if("${channelId}" != ""){
			var url = "${ctx}/wcm/manuscript/add.action?channelId=${channelId}&flag=1";
		   if ($.isFunction(window.parent.addTab)){
				window.parent.addTab('添加稿件',url,'icon-dept');
			}else{
			  /**
				$('#manuscriptAddFrame').html('');
				$('#manuscriptAddWin').css({"width":widthcount,"height":"450px","left":leftcount});
				$('#manuscriptAddFrame').attr("src",url);
				$('#manuscriptAddWin').panel('setTitle','添加稿件');
				$('#manuscriptAddWin').window('open');
				**/
				window.location.href=url;
			}
		}else{
		  $.messager.alert('提示', '请选 择稿件所属栏目 ', 'info');
		}
	}

function getSelected() {
	var selected = $('#manuscriptList').datagrid('getSelected');
	if (selected) {
		return selected;
	} else {
		$.messager.alert('提示', '请选择要操作的数据', 'info');
	}
}

  function reload(){
	  $('#manuscriptList').datagrid('reload');
  }
function manuscriptQuery(){					
    var queryParams = $('#manuscriptList').datagrid('options').queryParams;
      queryParams.title = $('#title').val();
      queryParams.channelId = $('#channelId').val();
      queryParams.status = $('#status').val();
      var options = $('#manuscriptList').datagrid('getPager').data("pagination").options;  
        options.pageNumber=1;  
        options.total=0;  
        options.pageSize=10; 
      reload(); 
  }
  
  function publish(manuscriptId){
	  $.messager.confirm('确认', '您确定要发布？',
		   function(r) {
				if (r) {
					$.ajax( {
							type : "post",
							url : "${ctx}/wcm/manuscript/publish.action?type=publish&manuscriptId="+ manuscriptId,
							success : function(data, textStatus) {
								var result = jQuery.parseJSON(data);
								if(result.flag=="T"){
										publishArtice(manuscriptId);
								}else{
									$.messager.alert('提交结果', result.msg, 'error');
								}
							}
					});
				}
		});
  }
  
  function  publishArtice(articeId){
  	  $.ajax( {
  			type : "post",
  			url : "${ctx}/artice/publish.action?manuscriptId="+articeId,
  			success : function(data, textStatus) {
  				var result = jQuery.parseJSON(data);
  				if(result.flag=="T"){
  					$.messager.alert('结果', '操作成功', 'info',function(){
  						reload();
  					});
  				}
  			}
  	   });
    }
  
  function unpublish(manuscriptId){
	  $.messager.confirm('确认', '您确定要撤销发布？',
			   function(r) {
					if (r) {
						$.ajax( {
								type : "post",
								url : "${ctx}/wcm/manuscript/publish.action?type=unPublish&manuscriptId="+ manuscriptId,
								success : function(data, textStatus) {
									var result = jQuery.parseJSON(data);
									if(result.flag=="T"){
										$.messager.alert('结果', '操作成功', 'info');	
										reload();
									}else{
										$.messager.alert('提交结果', result.msg, 'error');
									}
								}
						});
					}
			});
  }
</script>
	</body>
</html>